/**
 * @project_name staff_vehicle
 * @package_name com.ssh.dao
 * @desc TODO
 * @param
 * @author jack
 * @date 2013-4-24
 * @time 下午10:54:37
 */
package com.ssh.dao;

import java.util.List;

import org.hibernate.SessionFactory;

import com.ssh.entity.DLicence;
import com.ssh.entity.FcarCard;

/**
 * @author jack
 *
 */
public class FcarCardDAOImpl implements FcarCardDAOI {
	private SessionFactory sessionFactory;

	/* (non-Javadoc)
	 * @see com.ssh.dao.FcarCardDAOI#queryById(java.lang.String)
	 */
	@Override
	public FcarCard queryById(String id) {
		// TODO Auto-generated method stub
		FcarCard fcarCard ;
		try{
			String hql = "from FcarCard as f where f.fcarcardId=?";
			fcarCard =
					(FcarCard) sessionFactory.getCurrentSession().
					createQuery(hql).setString(0, id).uniqueResult();
		}
		catch(Exception e){
			return null;
		}

		return fcarCard ;
	}

	/* (non-Javadoc)
	 * @see com.ssh.dao.FcarCardDAOI#updateByDL(com.ssh.entity.FcarCard)
	 */
	@Override
	public FcarCard updateByFC(FcarCard fcarCard) {
		// TODO Auto-generated method stub
		try{
			sessionFactory.getCurrentSession().save(fcarCard);
		}
		catch(Exception e){
			return null;
		}

		return fcarCard;
	}

	/* (non-Javadoc)
	 * @see com.ssh.dao.FcarCardDAOI#deleteById(java.lang.String)
	 */
	@Override
	public int deleteById(String id) {
		// TODO Auto-generated method stub
		int num ;
		try{
			String hql = "delete FcarCard as f where f.id=?";
			num = sessionFactory.getCurrentSession().createQuery(hql).setString(0, hql).executeUpdate();
		}
		catch(Exception e){
			return 0 ;
		}
		return num;
	}

	/* (non-Javadoc)
	 * @see com.ssh.dao.FcarCardDAOI#addFcarCard(com.ssh.entity.FcarCard)
	 */
	@Override
	public FcarCard addFcarCard(FcarCard fcarCard) {
		// TODO Auto-generated method stub
		try{
			sessionFactory.getCurrentSession().save(fcarCard);
		}
		catch(Exception e){
			return null;
		}
		return fcarCard;
	}

	/* (non-Javadoc)
	 * @see com.ssh.dao.FcarCardDAOI#addFcarCardList(java.util.List)
	 */
	@Override
	public int addFcarCardList(List<FcarCard> fcarCardList) {
		// TODO Auto-generated method stub
		int length = fcarCardList.size();
		try{
			for(int i=0;i<length;i++){
				addFcarCard(fcarCardList.get(i));
			}
		}
		catch(Exception e){
			return 0;
		}

		return length;
	}

	/* (non-Javadoc)
	 * @see com.ssh.dao.FcarCardDAOI#queryByIdList(java.lang.String)
	 */
	@Override
	public List<FcarCard> queryByIdList(String strings) {
		// TODO Auto-generated method stub
		return null;
	}

	/* (non-Javadoc)
	 * @see com.ssh.dao.FcarCardDAOI#countById(java.lang.String)
	 */
	@Override
	public int countById(String id) {
		// TODO Auto-generated method stub
		return 0;
	}

	/* (non-Javadoc)
	 * @see com.ssh.dao.FcarCardDAOI#deleteByobject(com.ssh.entity.FcarCard)
	 */
	@Override
	public int deleteByobject(FcarCard fcarCard) {
		// TODO Auto-generated method stub
		try{
			sessionFactory.getCurrentSession().delete(fcarCard);
		}
		catch(Exception e){
			return 0 ;
		}
		return 1;
	}

	/**
	 * @return the sessionFactory
	 */
	public SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	/**
	 * @param sessionFactory the sessionFactory to set
	 */
	public void setSessionFactory(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

}
